/* $Id: RankingComparator.java 39 2009-07-24 22:48:06Z h_m_r@gmx.de $ */
package org.jugger.tournament.model.ranking;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;

import org.jugger.tournament.model.TeamStats;



/**
 * @author Sven Hamer
 */
public abstract class RankingComparator implements Comparator<TeamStats> {

	public int getAdditionalColumnCount() {
		return 0;
	}
	public String getAdditionalColumnName(int columnIndex) {
		return null;
	}
	public Object getAdditionalColumnValue(TeamStats teamStats, int columnIndex) {
		return null;
	}

	public String getPrefix() {
		String className = getClass().getSimpleName();
		return className.substring(0, className.length() - "RankingComparator".length());
	}


	public static Collection<RankingComparator> getAll() {
		Collection<RankingComparator> result = new ArrayList<RankingComparator>();
		result.add(new BuchholzRankingComparator());
		return result;
	}


	protected static HashMap<Class<?>, RankingComparator> instances = new HashMap<Class<?>, RankingComparator>();
	public static RankingComparator getFromPrefix(String prefix) {
		String name = prefix+"RankingComparator";
		try {

			Class<?> clazz = Class.forName(RankingComparator.class.getPackage().getName()+"."+name);
			return instances.get(clazz);
		} catch (ClassNotFoundException e) {
			// invalid class
		}
		return null;
	}

}
